package org.sja.log2traffic.dataStructures.simpleTime;

import java.util.HashMap;
import java.util.Map;

import org.sja.log2traffic.dataStructures.CounterForDateAndResponseTimeEntity;
import org.sja.log2traffic.dataStructures.DateAndResponseTimeEntity;
import org.sja.log2traffic.dataStructures.ICategoryTracker;
import org.sja.log2traffic.dataStructures.INewLogInfo;


public class LogDataSimpleTimeElement implements INewLogInfo {

	private Map<String, CounterForDateAndResponseTimeEntity> counterForDateAndResponseTimes = new HashMap<String, CounterForDateAndResponseTimeEntity>();
	private ICategoryTracker categoryTracker;

	public LogDataSimpleTimeElement(ICategoryTracker categoryTracker) {
		this.categoryTracker = categoryTracker;
	}

	public void accept(String category, DateAndResponseTimeEntity dateAndResponseTime) {
		CounterForDateAndResponseTimeEntity counterForDateAndResponseTime = counterForDateAndResponseTimes.get(category);
		if (counterForDateAndResponseTime == null) {
			counterForDateAndResponseTime = new CounterForDateAndResponseTimeEntity(category);
			counterForDateAndResponseTimes.put(category, counterForDateAndResponseTime);
		}
		counterForDateAndResponseTime.newDateAndResponseTime(dateAndResponseTime);

		if (categoryTracker != null) {
			categoryTracker.foundCategory(category, dateAndResponseTime);
		}

	}

	public CounterForDateAndResponseTimeEntity getRawDataElementForCategory(String categoryEnum) {
		return counterForDateAndResponseTimes.get(categoryEnum);
	}

}
